window.name ="NG_DEFER_BOOTSTRAP!";
init =false;
/**
 * easyui 和 anguarjs 结合有点勉强 让它先暂停 执行等到 ajax 加载后后再进行初始化NG
 */
$('#dataGrid').datagrid({
	url : PATH+'/business/zhuanye/list',
	fit : true,
	fitColumns : true,
	border : false,
	pagination : true,
	idField : 'zyDh',
	pageSize : 10,
	pageList : [ 10, 20, 30, 40, 50 ],
	sortName : 'zyDh',
	sortOrder : 'desc',
	checkOnSelect : false,
	selectOnCheck : false,
	nowrap : false,
	striped : true,
	rownumbers : true,
	singleSelect : true,
	frozenColumns : [ [ {
		field : 'zyDh',
		title : '代码',
		width : 150,
		sortable : true
	}, {
		field : 'zyMc',
		title : '名称',
		width : 220,
		sortable : true
	} ] ],
	columns : [ [ {
		field : 'action',
		title : '操作',
		width : 100,
		formatter : formatterFun
	} ] ],
	toolbar : '#toolbar',
	onLoadSuccess : function() {
		parent.$.messager.progress('close');
		$(this).datagrid('tooltip');
		if(!init){
		
			angular.resumeBootstrap();
			init=true;
		}
		
		
		
	},
	onRowContextMenu : function(e, rowIndex, rowData) {
		e.preventDefault();
		$(this).datagrid('unselectAll');
		$(this).datagrid('selectRow', rowIndex);
		$('#menu').menu('show', {
			left : e.pageX,
			top : e.pageY
		});
	}
});
MainApp.controller('ZhuanyeCtrls', [ '$scope', function($scope) {
$scope.load=function(){

};
$scope.deleteFun=function(id) {
	if (id == undefined) {
		var rows = $('#dataGrid').datagrid('getSelections');
		id = rows[0].zyDh;
	}
	parent.$.messager.confirm('询问', '您是否要删除当前记录？', function(b) {
		if (b) {
			parent.$.messager.progress({
				title : '提示',
				text : '数据处理中，请稍后....'
			});
			$.post(PATH+'/business/zhuanye/delete', {
				zydh : id
			}, function(result) {
				if (result.success) {
					$('#dataGrid').datagrid('reload');
				}
				else{
					  $.messager.alert('提示',result.data);
				}
				parent.$.messager.progress('close');
			}, 'JSON');
		}
	});
};
$scope.editFun=function(id) {
	if (id != undefined)$('#dataGrid').datagrid('selectRecord', id);
	var node = $('#dataGrid').datagrid('getSelected');
	if (node) {
		loadFrom('#fm',node);
		$('#zyDh').attr('readonly','readonly');
		showDialog('#dlg','编辑信息');
		url=PATH+'/business/zhuanye/edit';
	}
};

$scope.addFun=function() {
	  $('#fm').form('clear');
	  $('#zyDh').attr('readonly',false);
	  showDialog('#dlg','添加信息');
	  url=PATH+"/business/zhuanye/add";
	  
};
$scope.exportFun=function() {
			window.location.href=PATH+"/business/zhuanye/export";
};


$scope.submit=function(){
	
      $('#fm').form('submit',{
                url: url,
                success: function(result){
                 result= $.parseJSON(result);
                 if(result.success){
                  $('#dlg').dialog('close'); 
                  $('#dataGrid').datagrid('reload');
                  }
                else {
                  $.messager.alert('提示',result.data);
                }
             }
       });		
};
$scope.importExcelFun=function() {
		showDialog('#dlg2','导入excel');
};
$scope.submitImportExcel=function() {

    $('#fm2').form('submit',{
        url: PATH+'/business/zhuanye/importExcel',
        data:{file:$("#file").val()},
        success: function(result){
         result= $.parseJSON(result);
         
         if(result.success==true){
          $('#dlg2').dialog('close'); 
          $('#dataGrid').datagrid('reload');
          }
        else {
        	var string="<table border='1'><tr><th>所在列</th><th>消息</th>"
                $.each(result.data,function(i,v) {
                   string+="<tr><td>"+v.key+"</td><td>"+v.value+"</td></tr>";
                });
                string+="</table>";
        	 $('#dlg2').dialog('close');
        	 $('#ErrorContent').html(string);
        	 $('#w').window('open');
        }
     }
});
	


};
} ]);












 

